#include "GameHUD.h"

void UGameHUD::NativeConstruct()
{
	Super::NativeConstruct();
	AddButton -> OnClicked . AddDynamic(this, &ThisClass::Add);
	BackButton -> OnClicked . AddDynamic(this, &ThisClass::Back);
	NumberText -> SetText(FText::FromString("Num : " + FString::FromInt(Num)));
	Show();
}

APlayerController* UGameHUD::GetController()
{
	UWorld* World = GetWorld();
	if (World)
	{
		return World -> GetFirstPlayerController();
	}
	return nullptr;
}

void UGameHUD::Show()
{
	APlayerController* PlayerController = GetController();
	if (PlayerController)
	{
		PlayerController -> SetInputMode(FInputModeUIOnly());
		PlayerController -> SetShowMouseCursor(true);
		AddButton -> SetVisibility(ESlateVisibility::Visible);
		BackButton -> SetVisibility(ESlateVisibility::Visible);
	}
}

void UGameHUD::Add()
{
	Num++;
	NumberText -> SetText(FText::FromString("Num : " + FString::FromInt(Num)));
}

void UGameHUD::Back()
{
	APlayerController* PlayerController = GetController();
	if (PlayerController)
	{
		PlayerController -> SetInputMode(FInputModeGameOnly());
		PlayerController -> SetShowMouseCursor(false);
		AddButton -> SetVisibility(ESlateVisibility::Hidden);
		BackButton -> SetVisibility(ESlateVisibility::Hidden);
	}
}
